package BaseObject;

import java.util.Random;

public class Tools {

	public static double Exp(double lambda) { 
		Random rand = new Random(); 
		return - (1 / lambda) * Math.log( 1 - rand.nextDouble() ); 
		}

	public static double N(double average, double variance, double number)
	{
	double newNormalLaw = (number - average)/ variance;
	return NCR(newNormalLaw);
	}
	
	public static double NCR(double z) {
		   double f;
		   double u;
		   double s;
		   double t;
		   double s1;
		   double res;
	 
		   u = z * z;
		   if (u > 55.5) {
			   if (z > 0) {
				   res = 1;
			   }
			   else {
				   res = 0;
			   }
		   }
	 
		   else {
		      s = 0;
		      t = 1;
		      f = 3;
		      do {
		         s1 = s;
		         s = s + t;
		         t = t * u / f;
		         f = f + 2;
		      }while (s != s1);
		      res = z * s / Math.pow((8 * Math.atan(1) * Math.exp(u)) , 0.5) + 0.5;
		   }
		   return res;
		}
}
